package Thread;
//单例模式之懒汉模式(高性能但不安全,需要加锁)

class SingleLazy {
    private volatile static SingleLazy instance = null;

    public static SingleLazy getInstance() {
        if (instance == null) {
            synchronized (SingleLazy.class) {
                if (instance == null) {
                    instance = new SingleLazy();
                }
            }
        }
        return instance;
    }

    public SingleLazy() {

    }
}

public class ThreadDemo25 {

    public static void main(String[] args) {
        SingleLazy singleLazy1 = SingleLazy.getInstance();
        SingleLazy singleLazy2 = SingleLazy.getInstance();
        System.out.println(singleLazy1 == singleLazy2);

    }

}
